/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package NetworkRequests;

import Common.NetworkManager;
import java.io.*;
import javax.microedition.io.*;
import Enum.ConnectType.*;

/**
 *
 * @author Hmong
 */
public class CMNetHttpRequest extends NetworkTestRequest {

    public void run() {
        boolean bSuceess = false;

        try {
            String netAddress = "http://hmongsoft.com/Name.txt";
            HttpConnection http;//创建一个http的连接
            http = (HttpConnection) Connector.open(netAddress);
            http.setRequestMethod(HttpConnection.GET); //设置连接方式
            DataInputStream dis = http.openDataInputStream();//打开连接的输入流

            byte[] btData = new byte[1024];
            int nActualRead = dis.read(btData);
            if (0 < nActualRead){
                String strRead = new String(btData, 0, nActualRead, "UTF-8");
                System.out.println("CMNET Read: " + strRead);

                bSuceess = strRead.equalsIgnoreCase("NB");
            }
            
            dis.close();
            http.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }

        if (bSuceess){
            NetworkManager.ConnectSuccessfulType |= CMNet.Http;
            SetCommunicationSuccess(true);
        }

        NetworkManager.SetConnectTypeTested(CMNet.Http);
    }
}
